﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Ezhu.WPFWin.Base
{
    internal class BaseWindow
    {
        private const uint _sysCommand = 0x112;

        /// <summary>
        /// 根据拖拉的边框来激活发送消息
        /// </summary>
        /// <param name="hnwd"></param>
        /// <param name="directionName"></param>
        internal static void ResizeWind(IntPtr hnwd, string directionName)
        {
            //ResizeDirection direction = (ResizeDirection)Enum.Parse(typeof(ResizeDirection), directionName);
            int tempDirection;
            switch (directionName)
            {
                case "Left":
                    tempDirection = 1 << 0;
                    break;
                case "Right":
                    tempDirection = 1 << 1;
                    break;
                case "Top":
                    tempDirection = 3 << 0;
                    break;
                case "TopLeft":
                    tempDirection = 1 << 2;
                    break;
                case "TopRight":
                    tempDirection = 5 << 0;
                    break;
                case "Bottom":
                    tempDirection = 3 << 1;
                    break;
                case "BottomLeft":
                    tempDirection = 7 << 0;
                    break;
                case "BottomRight":
                    tempDirection = 2 << 2;
                    break;
                default:
                    tempDirection = 0;
                    break;
            }
            SendMessage(hnwd, _sysCommand, (IntPtr)(61440 + tempDirection), IntPtr.Zero);
        }

        #region 如需根据鼠标在界面上移动来动态判断，激活此段代码
        //internal enum ResizeDirection
        //{
        //    Left = 1,
        //    Right = 2,
        //    Top = 3,
        //    TopLeft = 4,
        //    TopRight = 5,
        //    Bottom = 6,
        //    BottomLeft = 7,
        //    BottomRight = 8,
        //}


        /// <summary>
        /// 根据每个角度对应有不同的pointer
        /// </summary>
        //internal Dictionary<ResizeDirection, System.Windows.Input.Cursor> cursors = new Dictionary<ResizeDirection, System.Windows.Input.Cursor>
        //{
        //    {ResizeDirection.Top,System.Windows.Input.Cursors.SizeNS},
        //    {ResizeDirection.TopLeft,System.Windows.Input.Cursors.SizeNWSE},
        //    {ResizeDirection.TopRight,System.Windows.Input.Cursors.SizeNESW},
        //    {ResizeDirection.Bottom,System.Windows.Input.Cursors.SizeNS},
        //    {ResizeDirection.BottomLeft,System.Windows.Input.Cursors.SizeNESW},
        //    {ResizeDirection.BottomRight,System.Windows.Input.Cursors.SizeNWSE},
        //    {ResizeDirection.Left,System.Windows.Input.Cursors.SizeWE},
        //    {ResizeDirection.Right,System.Windows.Input.Cursors.SizeWE}
        //};

        #endregion

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        internal static extern IntPtr SendMessage(IntPtr hwnd, uint msg, IntPtr wParam, IntPtr lParam);
    }
}
